<?php
/**
 * Created by PhpStorm.
 * User: Lin
 * Date: 2017/2/27 0027
 * Time: 下午 17:26
 */
Class IndexAction extends Action{

    //前台首页视图
    public function index(){
        import('Class.Category',APP_PATH);
        import('Class.Goods',APP_PATH);
        if((!$goodsArr=S('goodsArr'))||(!$cateList=S('cateList'))){
            $cate=M('cate')->field(array('id','cate_name','parent_id'))->order('sort DESC')->where(array('is_show'=>1,'is_nav'=>1))->select();
            $cateList=Category::unlimitedForLayer($cate);
            $cateId=M('cate')->field(array('id'))->order('sort DESC')->where(array('is_show'=>1,'is_nav'=>1,'parent_id'=>0))->select();
            foreach($cateId as $k=>$v){
                $cateArr[$k]=Category::findCatesByCate($cate,$v['id']);
                $goodsArr[$k]=Goods::findGoodsInCateIdArr($cateArr[$k]);
            }
            S('goodsArr',$goodsArr,60);
            S('cateList',$cateList,60);
        }
        $this->cateArr=$cateList;
        $this->goodsArr=$goodsArr;
        $this->display();
    }

    //退出登录
    Public function logout(){
        session_unset();
        session_destroy();
        $this->redirect(GROUP_NAME.'/Index');
    }
}